/*
 * Copyright (c) 2021.版权所有高金磊
 */

package 领扣算法.A简单题.长按键入;

import java.util.LinkedList;

public class Main {

    public boolean isLongPressedName(String name, String typed) {
        char[] name_c=name.toCharArray(),typed_c=typed.toCharArray();
        StringBuilder stringBuilder_name=new StringBuilder(),stringBuilder_type=new StringBuilder();
        LinkedList<Integer> name_num=new LinkedList<>(),type_num=new LinkedList<>();
        char middle=1;
        int count=0;
        for (char c : name_c) {
            if (c!=middle){
                middle=c;
                name_num.addLast(count);
                count=0;
                stringBuilder_name.append(c);
            }
            count++;
        }
//        stringBuilder_name.append(name_c[name_c.length-1]);
        name_num.addLast(count);
        middle=1;
        count=0;
        for (char c : typed_c) {
            if (c!=middle){
                stringBuilder_type.append(c);
                type_num.addLast(count);
                middle=c;
                count=0;
            }
            count++;
        }
//        stringBuilder_type.append(typed_c[typed_c.length-1]);
        type_num.addLast(count);
        if (stringBuilder_name.toString().equals(stringBuilder_type.toString())){
            while (!type_num.isEmpty()){
                if (type_num.pollFirst()<name_num.pollFirst()){
                    return false;
                }
            }
            return true;
        }
        return false;
    }
    public static void main(String arg[]){//main--来自高金磊
    
        new Main().isLongPressedName("saeed"
                ,"ssaaedd");
    }
}
